package com.ymttest.database.sqlwapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.YmtCouponActivity;
import com.ymttest.database.model.YmtCouponActivityBatch;
import com.ymttest.database.model.YmtCouponActivityNewUserBound;
import com.ymttest.database.model.YmtCouponActivityPregenerate;
import com.ymttest.database.model.YmtCouponVirtualRelation;
import com.ymttest.utils.EnvSetup;

public class YmtCouponActivityWapper {
	SqlManager manage;

	public YmtCouponActivityWapper() {
		manage = new SqlManager("ymt" + EnvSetup.getEnv());
	}
	
	public List<YmtCouponActivity> selectTop1NewUserCouponActivity() throws InterruptedException {

		List<YmtCouponActivity> results = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtCouponActivityMapper.selectTop1NewUserActivity", null);

		// manage.close();
		return results;
	}

	public List<YmtCouponActivityNewUserBound> selectTop1CouponActivityNewUserBound() throws InterruptedException {

		List<YmtCouponActivityNewUserBound> results = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtCouponActivityNewUserBoundMapper.selectTop1YmtCouponActivityNewUserBound", null);

		// manage.close();
		return results;
	}
	
	public List<YmtCouponActivityNewUserBound> selectTop1YmtCouponActivityNewUserBoundByCouponSendStatus(int couponSendStatus) throws InterruptedException {

		List<YmtCouponActivityNewUserBound> results = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtCouponActivityNewUserBoundMapper.selectTop1YmtCouponActivityNewUserBoundByCouponSendStatus", couponSendStatus);

		return results;
	}
	
	public List<YmtCouponActivity> selectCouponActivityByActivityCode(int activityCode) throws InterruptedException {

		List<YmtCouponActivity> results = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtCouponActivityMapper.selectCouponActivityByActivityCode", activityCode);

		// manage.close();
		return results;
	}
	
	public List<YmtCouponActivity> selectCouponActivityByActivityChannel(String activityChannel) throws InterruptedException {

		List<YmtCouponActivity> results = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtCouponActivityMapper.selectCouponActivityByActivityChannel", activityChannel);

		// manage.close();
		return results;
	}
	
	public List<YmtCouponActivityNewUserBound> selectCouponActivityNewUserBoundByMobilePhoneAndActivityCode(String mobilePhone, int activityCode) throws InterruptedException {

		  Map m = new HashMap();
	        m.put("mobilePhone", mobilePhone);
	        m.put("activityCode", activityCode);
	        
		List<YmtCouponActivityNewUserBound> results = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtCouponActivityNewUserBoundMapper.selectCouponActivityNewUserBoundByMobilePhoneAndActivityCode", m);

		// manage.close();
		return results;
	}
	
	public List<YmtCouponActivityNewUserBound> selectCouponActivityNewUserBoundByUserIdAndActivityCode(String userId, int activityCode) throws InterruptedException {

		  Map m = new HashMap();
	        m.put("userId", userId);
	        m.put("activityCode", activityCode);
	        
		List<YmtCouponActivityNewUserBound> results = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtCouponActivityNewUserBoundMapper.selectCouponActivityNewUserBoundByUserIdAndActivityCode", m);

		// manage.close();
		return results;
	}

	public List<YmtCouponActivityBatch> selectYmtCouponActivityBatchByActivityCode(int activityCode) throws InterruptedException {
	        
		List<YmtCouponActivityBatch> results = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtCouponActivityBatchMapper.selectYmtCouponActivityBatchByActivityCode", activityCode);

		// manage.close();
		return results;
	}
	
	public List<YmtCouponActivityPregenerate> selectTop1UsedPregenerateCodeByActivityCode(int activityCode) throws InterruptedException {
        
		List<YmtCouponActivityPregenerate> results = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtCouponActivityPregenerateMapper.selectTop1UsedPregenerateCodeByActivityCode", activityCode);

		// manage.close();
		return results;
	}
	
	public List<YmtCouponActivityPregenerate> selectTop1UnUsedPregenerateCodeByActivityCode(int activityCode) throws InterruptedException {
        
		List<YmtCouponActivityPregenerate> results = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtCouponActivityPregenerateMapper.selectTop1UnUsedPregenerateCodeByActivityCode", activityCode);

		// manage.close();
		return results;
	}
	
	public List<Map> selectGetUserReceiveList() throws InterruptedException {

		List<Map> results = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtCouponActivityNewUserBoundMapper.selectGetUserReceiveList", null);

		// manage.close();
		return results;
	}
	
	public List<Map> selectGetUserReceiveListByUserId(String userId) throws InterruptedException {
		  Map m = new HashMap();
	        m.put("userId", userId);

		List<Map> results = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtCouponActivityNewUserBoundMapper.selectGetUserReceiveListByUserId", m);

		// manage.close();
		return results;
	}
	
	public List<YmtCouponVirtualRelation> selectCouponVirtualRelationByCouponCodeAndVirtualCouponCode(String couponCode, String virtualCouponCode) throws InterruptedException {
		  Map m = new HashMap();
	        m.put("couponCode", couponCode);
	        m.put("virtualCouponCode", virtualCouponCode);
	        
		List<YmtCouponVirtualRelation> results = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtCouponVirtualRelationMapper.selectCouponVirtualRelationByCouponCodeAndVirtualCouponCode", m);

		// manage.close();
		return results;
	}
	
	public List<YmtCouponVirtualRelation> selectTop1CouponVirtualRelation() throws InterruptedException {

		List<YmtCouponVirtualRelation> results = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtCouponVirtualRelationMapper.selectTop1CouponVirtualRelation", null);

		// manage.close();
		return results;
	}
	
	public void setNeedCancelVirtualCoupon() {

		int i=manage.update(
						"com.ymttest.database.mapping.YmtCouponVirtualRelationMapper.setNeedCancelVirtualCoupon",
						null);
		manage.commit();
	}
	
	public List<YmtCouponVirtualRelation> getNeedCancelVirtualCoupon() throws InterruptedException {

		List<YmtCouponVirtualRelation> results = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtCouponVirtualRelationMapper.getNeedCancelVirtualCoupon", null);

		// manage.close();
		return results;
	}
}
